/*
 * Camera.cpp
 *
 *  Created on: 2012/9/25
 *      Author: apple
 */
#include "Camera.h"
//#include "math/ck_vec.h"

struct CK_API ckVec;
namespace wild
{
namespace android
{

//namespace wild
Camera::Camera(const std::string& name, wild::SceneRoleMgr* sm)
: m_poMgr( sm )
{
	m_scr = ckDrawMgr::getScreen(ckDrawMgr::DEFAULT_3D_SCREEN_ID);
}
Camera::~Camera()
{

}
void Camera::move(const ckVec& vec)
{
	m_vEyes = m_vEyes + vec;

	DoUpdate();
}
void Camera::setPosition(const ckVec& vec)
{
	m_vEyes = vec;

	DoUpdate();
}
void Camera::setPosition(r32 x,r32 y,r32 z)
{
	//m_vEyes.ckVec(x,y,z);
	m_vEyes.x =x;
	m_vEyes.y = y;
	m_vEyes.z = z;
	DoUpdate();
}
const ckVec& Camera::getPosition(void) const
{
	return m_vEyes;
}
void Camera::setDirection(r32 x, r32 y, r32 z)
{

}
void Camera::setDirection(const ckVec& vec)
{

	//ckMat::UNIT.rotateY_r32(m_rot_y).rotateX_r32(m_rot_x).translate(0.0f, 150.0f, 1000.0f + m_rot_x * m_rot_x * 0.1f);
}
void Camera::rotate(r32 x, r32 y, r32 z)
{
	ckMat oMatbuf_ = ckMat::UNIT;
	oMatbuf_.rotateY_r32(y);
	oMatbuf_.rotateX_r32(x);
	oMatbuf_.translate(0.0f, 150.0f, 1000.0f + x * x * 0.1f);
	//m_scr->view() = oMatbuf_;

	this->m_poMgr->ComponentProc(T3D_EM_CAMERAMOVE, 0, (char*)&oMatbuf_);
}
void Camera::rotate(const ckVec& vec)
{
	rotate(vec.x,vec.y,vec.z);

	DoUpdate();
}
ckVec Camera::getDirection(void) const
{
	ckVec kk;

	kk = m_vTarget - m_vEyes;

	return kk;
}
void Camera::LookAt(const ckVec &eye,const ckVec &target,const ckVec &up)
{
	m_vEyes = eye;
	m_vTarget = target;
	m_vUp = up;

	DoUpdate();
}

void Camera::DoUpdate()
{
	ckMat oMatbuf_ = ckMat::UNIT;
	ckMat set_ = oMatbuf_.lookAt(m_vEyes,m_vTarget,m_vUp);

	//m_scr->view() = set_;

	this->m_poMgr->ComponentProc(T3D_EM_CAMERAMOVE, 0, (char*)&set_);
}

}	//	namespace android

}	//	namespace wild


